package cn.pxs.service;

import cn.pxs.entity.ItemBook;
import cn.pxs.entity.OrdInfo;
import cn.pxs.entity.Order;
import cn.pxs.entity.OrderLine;
import cn.pxs.mapper.OrdMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//订单业务接口实现类
@Service
public class OrdServiceImpl implements OrdService {
    @Autowired
    private OrdMapper ordMapper;

    ///api/fore/ord
    @Override
    public List<ItemBook> findItemInfoByOrdid(Integer ordid) {
        return ordMapper.findItemInfoByOrdid(ordid);
    }
    //更新发货地址及电话
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateAddr(Order order){
        ordMapper.updateAddr(order);
    }
    //更新付款标识
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Order updatePay(Order order) {
        order.setTpay(new Date());
        ordMapper.updatePay(order);
        return ordMapper.findOrderByOrdid(order.getOrdid());
    }
    //根据 ordid 查询 Order
    @Override
    public Order findOrderByOrdid(Integer ordid) {
        return ordMapper.findOrderByOrdid(ordid);
    }
    //查找该登录用户的所有订单头信息
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OrderLine> findOrdLines(Object user, OrderLine orderLine,
                                        String tstart,
                                        String tend) {
        return ordMapper.findOrdLines(user,orderLine,tstart,tend);
    }
    //查找该登录用户的所有订单头信息
    @Override
    public List<OrderLine> findOrdLineByPage(Object user, OrderLine orderLine,
                                             Map map) {

        return ordMapper.findOrdLineByPage(user, orderLine,map);
    }
    @Override
    //查找该登录用户的所有订单头信息  的行数
    public int findOrdLineByPageLine(Object user, OrderLine orderLine, Map map) {
        return ordMapper.findOrdLineByPageLine(user, orderLine, map);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    //根据登录用户，id 查找订单头信息
    public OrdInfo findInfoByOrdid(Object user, Integer ordid) {
        return ordMapper.findInfoByOrdid(user, ordid);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    //添加订单
    public void addOrd(Object user, Order order) {
       ordMapper.addOrd(user,order);
    }





    ///api/adm/ord/
    @Override
    public void updateShip(Order order) {
        ordMapper.updateShip(order);
    }
    //    /findOrdInfo
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OrderLine> findOrdInfo(Integer start,Integer num,OrderLine orderLine,Map map) {
       return  ordMapper.findOrdInfo(start, num, orderLine,map);
    }
    ///findOrdInfo的行数
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int findOrdInfoLine(OrderLine orderLine,Map map) {
        return ordMapper.findOrdInfoLine(orderLine,map);
    }
}
